#include "arrayStack.h"
#include <stdio.h>
#include <stdlib.h>

void initArrayStack(ArrayStack_t *stack, int n) {
    stack->data = malloc(sizeof(Element_t) * n);
    stack->pos = -1;
    stack->capacity = n;
}

void releaseArrayStack(ArrayStack_t *stack) {
    if(stack==NULL) return;

}

int pushArrayStack(ArrayStack_t *stack, Element_t value) {
    if (stack->pos >= stack->capacity-1 ) {
        printf("push Error: stack is full\n");
        return -1;
    }
    stack->pos++;
    stack->data[stack->pos] = value;
    return 0;
}

int popArrayStack(ArrayStack_t *stack) {
    if (stack->pos == -1) {
        printf("pop Error: stack is empty\n");
        return -1;
    }
    stack->pos--;
    return 0;
}

Element_t getTopArrayStack(const ArrayStack_t *stack) {
    if (stack->pos == -1) {
        printf("getTop Error: stack is empty\n");
        return -1;
    }
    return stack->data[stack->pos];
}

bool emptyArrayStack(const ArrayStack_t *stack) {
    return stack->pos == -1;
}
